package cn.dengta.webapp.user.entity;

import java.util.Date;

import cn.dengta.common.model.*;
import cn.dengta.webapp.base.entity.BizEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.X;

/**
 * 曝光购买日志记录
 *
 * @author lgy
 * @since 2022-04-19
 */
@Setter
@Getter
@Accessors(chain = true)
public class RecExposureLog extends BizEntity {

	/** 用户ID */
	private Long userId;
	/** 0:免费 1：扣费 */
	private ExposureType type;
	/** 关联的业务实体ID */
	private Long userCoinLogId;
	/** 旧字段信息 */
	private String old;
	/** 新字段信息 */
	private String current;
	/** 时长（分） */
	private Integer changeMinute;

	private transient Integer vipPerLimit;

	public RecExposureLog init(Long userId, ExposureType type, Long userCoinLogId, Integer changeMinute, Date now) {
		this.userId = userId;
		this.type = type;
		this.changeMinute = changeMinute;
		this.old = "";
		this.current = "";
		this.userCoinLogId = userCoinLogId;
		this.init(Status.NO.value, State.PUBLIC);
		this.initTime(now);
		return this;
	}

	public boolean isSTD() {
		return ExposureType.STD == type;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer defaultVipPerLimit() {
		return X.expectNotNull(vipPerLimit, 1);
	}

	@Getter
	public enum ExposureType implements ValueProxyImpl<ExposureType, Integer> {

		/** VIP */
		VIP(0, "VIP"),
		/** 标准 */
		STD(1, "标准"),
		//
		;

		// 定义私有变量
		public final Integer value;
		final ValueProxy<ExposureType, Integer> proxy;

		// 构造函数，枚举类型只能为私有
		ExposureType(Integer value, String label) {
			this.value = value;
			this.proxy = new ValueProxy<>(this, value, label);
		}

		public static ExposureType[] getValues() {
			return ValueProxy.getCachedArray(ExposureType.class, ExposureType::values);
		}

		public static ExposureType of(Integer value) {
			return VIP.getValueOf(value);
		}
	}

}
